package com.approval.approvalapp.center.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.center.acitivty.ThingsCensusDetailActivity;
import com.approval.approvalapp.center.bean.ProvinceCensusBean;
import com.approval.approvalapp.center.bean.ThingsCensusBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * @author superman
 * @date 2019/5/9
 */
public class ThingsCensusAdapter extends BaseRecycleListAdapter<ThingsCensusBean.ListBean> {


    boolean isallsheng;

    public void setIsallsheng(boolean isallsheng) {
        this.isallsheng = isallsheng;
        notifyDataSetChanged();
    }

    public ThingsCensusAdapter(List<ThingsCensusBean.ListBean> mList, Context context) {
        super(mList, context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.things_census_item;
    }

    @Override
    public RecyclerView.ViewHolder createHolder(View view) {
        return new ViewHolder(view);
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, ThingsCensusBean.ListBean bean, int position) {
        if (holder instanceof ViewHolder) {
            ((ViewHolder) holder).setData(bean);
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_name1)
        TextView tvName1;
        @Bind(R.id.tv_name2)
        TextView tvName2;
        @Bind(R.id.tv_name3)
        TextView tvName3;
        @Bind(R.id.tv_name4)
        TextView tvName4;
        @Bind(R.id.tv_name5)
        TextView tvName5;
        @Bind(R.id.tv_name6)
        TextView tvName6;
        @Bind(R.id.root)
        LinearLayout root;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void setData(final ThingsCensusBean.ListBean bean) {

//            if (bean.getTitle().contains("市")){
//                root.setBackgroundColor(Color.parseColor("#E8EDF7"));
//            }else {
//                root.setBackgroundColor(Color.parseColor("#ffffff"));
//            }

            tvName1.setText(bean.getTitle() + "");
            tvName2.setText(bean.getTotal_num() + "");
            tvName3.setText(bean.getBjsx_num() + "");
            tvName4.setText(bean.getWbj_num() + "%");
            tvName5.setText(bean.getSjwbj_num() + "%");
            tvName6.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    //全省
                    if (isallsheng) {
                        ThingsCensusDetailActivity.goInto(context, bean.getRegion_code(), "2");
                    } else {
                        //省级
                        ThingsCensusDetailActivity.goInto(context, bean.getRegion_code(), "1");
                    }
                }
            });

            if (isallsheng) {
                tvName3.setVisibility(View.VISIBLE);
            } else {
                tvName3.setVisibility(View.GONE);
            }
        }
    }
}
